package com.lmh.graphdisease.service.impl;

import com.lmh.graphdisease.entity.ProducerEntity;
import com.lmh.graphdisease.repository.DrugRepository;
import com.lmh.graphdisease.service.DrugService;
import com.lmh.graphdisease.utils.MatchEntityCastUtil;
import org.neo4j.driver.internal.value.NodeValue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lmh
 * @desc
 * @date 2023/3/9
 */
@Service
public class DrugServiceImpl implements DrugService {

    @Autowired
    private DrugRepository drugRepository;

    @Override
    public List<ProducerEntity> getDrugsOf(String name,int num) {
        List<NodeValue> result = drugRepository.getDrugOf(name,num);
        List<ProducerEntity> producerEntities = new ArrayList<>();
        for (NodeValue nodeValue:result){
            producerEntities.add(MatchEntityCastUtil.MatchToProducerEntity(nodeValue));
        }
        return producerEntities;
    }
}
